<?php

namespace App\Observers;

use App\Models\Log;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;

/**
 * Class UserObserver
 * 模型事件观察器 需在模型上使用 observe 方法,也可在服务提供器中的 boot 方法中注册观察器
 * @package App\Observers
 */
class PermissionObserver
{
    protected $user;

    public function __construct()
    {
        $this->user=Auth::user();
    }
    /**
     * 监听用户删除事件。
     *
     * @param  User  $user
     * @return void
     */
    public function deleting()
    {
        Log::firstOrCreate(['user_id'=>$this->user->id,'user_name'=>$this->user->name,'time'=>Carbon::now(),'opration'=>'删除权限']);
    }

    public function updating(){
        Log::firstOrCreate(['user_id'=>$this->user->id,'user_name'=>$this->user->name,'time'=>Carbon::now(),'opration'=>'修改权限信息']);
    }

    public function creating(){
        Log::firstOrCreate(['user_id'=>$this->user->id,'user_name'=>$this->user->name,'time'=>Carbon::now(),'opration'=>'添加权限']);
    }
}